import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
class Student implements Comparable<Student> {
       int age ;
    @Override
    public int compareTo(Student o) {
        if(this.age > o.age){
            return -1;
        }else if(this.age < o.age){
            return 1 ;
        }else{
            return 0;
        }
    }

    public Student(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
    
}


public class Test1 {
    public int[] smallestK(int[] arr, int k) {
        int[] elem = new int[k];
        if(arr.length == 0 || k <= 0){
            return elem;
        }
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new IntCmp());
        for(int i = 0 ; i<k ; i++){
            priorityQueue.offer(arr[i]);
        }
        for(int i=k ; i < arr.length ; i++){
            if(arr[i] < priorityQueue.peek()){
                priorityQueue.poll() ;
                priorityQueue.offer(arr[i]);
            }
        }
        for(int i = 0 ; i<k ; i++){
            elem[i] = priorityQueue.poll() ;
        }

        return elem ;

    }
    public static void main(String[] args) {
         PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new IntCmp());
         priorityQueue.offer(1);
         priorityQueue.offer(2);
        priorityQueue.offer(3);
        priorityQueue.offer(4);
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());

    }




}

class IntCmp implements Comparator<Integer>{

    @Override
    public int compare(Integer o1, Integer o2) {
        return o2-o1;
    }
}